module.exports = (req, res, next) => {
	res.execSql = (sql, callback) => {
		// 1.0 导入
		const mysql = require('mysql');
		// 2.0 创建连接
		const conn = mysql.createConnection({
			host: '127.0.0.1',
			port: 3306,
			user: 'root',
			password: '991220',
			database: 'takeout'
		});
		// 3.0 连接
		conn.connect();
		// 4.0 开始查询
		const result = new Promise((reslove, reject) => {
			conn.query(sql, (err, res) => {
				if (err) return console.log(err)
				reslove(res)
				if (callback) callback(res);
			})
		})
		// 5.0 断开连接
		conn.end();
		return result
	}
	next()
}
